package com.fyzk.activity.lottery.jc.football;


import com.fyzk.activity.lottery.jc.football.adapter.JCZQ_ZJQ_ZhiFuAdapter;
import com.fyzk.activity.lottery.jc.football.guoguan.JC_GuoGuanDialog;
import com.fyzk.activity.lottery.jc.football.guoguan.JC_GuoGuanInfor;
import com.fyzk.activity.lottery.zc.tz_dialog.ZCBF_infor;
import com.fyzk.activity.zhifu.SportsFootballPayActivity;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class JCZQ_ZJQ_ZhiFuActivity extends SportsFootballPayActivity {

    @Override
    protected void onResume() {
        super.onResume();
        buyType.setText("竞彩足球-总进球");
    }

    @Override
    protected void clear() {
        // TODO Auto-generated method stub
        super.clear();
        for (int i = 0; i < infos.size(); i++) {
            JCInfo info = infos.get(i);
            if (info.getOnclikNum() > 0) {
                info.setOnclikNum(0);
                Set<String> keys = info.btnHGPojo.keySet();
                for (String key : keys) {
                    info.btnHGPojo.get(key).isSel = false;
                }
            }
            List<ZCBF_infor> touZhu = info.getTouZhuInfor();
            for (int j = 0; j < touZhu.size(); j++) {
                touZhu.get(j).setSelect(false);
            }
            info.setResult("");
        }
        adapter.setInfors(infos, isDanguan);
        adapter.notifyDataSetChanged();
    }

    @Override
    protected void initAdapter() {
        adapter = new JCZQ_ZJQ_ZhiFuAdapter(this, isDanguan, infos, handler, this);
        listView.setAdapter(adapter);
    }


    /**
     * 获取投注内容   301012001-20140311002(3,4)|20140311004(2,3)^
     *
     * @param infos
     */
    public String getContent(List<JCInfo> infos, boolean isdanguan) {
        List<String> chuans = JC_GuoGuanInfor.getChuanIds(JC_GuoGuanDialog.result, isdanguan);
        StringBuffer content = new StringBuffer();
        for (int i = 0; i < chuans.size(); i++) {
            content.append(lotteryId);
            content.append(wanFa);
            content.append(chuans.get(i));
            content.append("-");
            List<String> singleTeamCodes = new ArrayList<>();
            List<String> singleTeamCodes_d = new ArrayList<>();
            for (int j = 0; j < infos.size(); j++) {
                JCInfo info = infos.get(j);
                StringBuffer danChang = new StringBuffer();
                if (info.getOnclikNum() > 0) {
                    danChang.append(info.getMatchNum());
                    danChang.append("(");
                    Set<String> keys = info.btnHGPojo.keySet();
                    Iterator<String> keyIterator = keys.iterator();
                    while (keyIterator.hasNext()) {
                        String key = keyIterator.next();
                        if (info.btnHGPojo.get(key).isSel) {
                            if (key.equals(info.SCORE_0)) {
                                danChang.append("0,");
                            } else if (key.equals(info.SCORE_1)) {
                                danChang.append("1,");
                            } else if (key.equals(info.SCORE_2)) {
                                danChang.append("2,");
                            } else if (key.equals(info.SCORE_3)) {
                                danChang.append("3,");
                            } else if (key.equals(info.SCORE_4)) {
                                danChang.append("4,");
                            } else if (key.equals(info.SCORE_5)) {
                                danChang.append("5,");
                            } else if (key.equals(info.SCORE_6)) {
                                danChang.append("6,");
                            } else if (key.equals(info.SCORE_7)) {
                                danChang.append("7,");
                            }
                        }
                    }
                    danChang.deleteCharAt(danChang.length() - 1);
                    danChang.append(")");
                    if (info.isDan()) {
                        singleTeamCodes_d.add(danChang.toString());
                    } else {
                        singleTeamCodes.add(danChang.toString());
                    }
                }
            }

            if (singleTeamCodes_d.size() > 0) {
                for (String team : singleTeamCodes_d) {
                    content.append(team);
                    content.append("|");
                }
                content = content.deleteCharAt(content.length()-1);
                content.append("#");
                for (String team : singleTeamCodes) {
                    content.append(team);
                    content.append("|");
                }
                content = content.deleteCharAt(content.length()-1);
                content.append("^!");
            } else {
                for (String team : singleTeamCodes) {
                    content.append(team);
                    content.append("|");
                }
                content = content.deleteCharAt(content.length() - 1);
                content.append("^!");
            }
        }
        return content.deleteCharAt(content.length() - 1).toString();
    }

    @Override
    protected int getMaxGuoGuan() {
        // TODO Auto-generated method stub
        return 6;
    }

    @Override
    public void open(JCInfo info) {

    }
}
